package com.edu.csu.smartfarm.common.domain.common;
import com.edu.csu.smartfarm.common.domain.constant.HttpStatus;

import java.util.HashMap;

/***
 * Class Encapsulates AjaxResult
 *
 */
public class AjaxResult extends HashMap<String, Object> {

    private static final long serialVersionUID = -1252714672854912496L;

    public static final String CODE_TAG = "code";

    public static final String MSG_TAG = "msg";

    public static final String DATA_TAG = "data";

    public AjaxResult(){
    }

    public AjaxResult(int code, String msg){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public AjaxResult(int code, String msg, Object data){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_TAG, data);
    }

    public static AjaxResult success(){
        return AjaxResult.success("success");
    }

    public static AjaxResult success(String msg){
        return AjaxResult.success(msg, null);
    }

    public static AjaxResult success(String msg, Object data){
        return new AjaxResult(HttpStatus.SUCCESS, msg, data);
    }

    public static AjaxResult error(String msg) {return AjaxResult.error(msg, null); }

    public static AjaxResult error(String msg, Object data) {return new AjaxResult(HttpStatus.ERROR, msg, data); }

    public static AjaxResult error(int code, String msg) { return new AjaxResult(code, msg, null); }
}
